package com.wzd.shoppingService;

import com.spring4all.swagger.EnableSwagger2Doc;
import com.wzd.AppConfig;
import com.wzd.cloud.RibbonTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@SpringBootApplication
@EnableTransactionManagement
@EnableScheduling
@EnableCaching
@EnableSwagger2Doc
@EnableDiscoveryClient
@EnableFeignClients
@EnableEurekaClient
@EnableHystrix
public class Application extends SpringBootServletInitializer {
    private static final Logger log = LoggerFactory.getLogger(com.wzd.Application.class);

    public Application() {
    }

    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(new Class[]{com.wzd.Application.class});
    }

    public static void main(String[] args) {
        ApplicationContext app = SpringApplication.run(com.wzd.Application.class, args);
        AppConfig config = (AppConfig) app.getBean(AppConfig.class);
        log.info("服务 {} 启动成功！", config.getName());
    }

    @Bean
    @LoadBalanced
    public RibbonTemplate restTemplate() {
        return new RibbonTemplate();
    }
}
